package com.anysoft.rrm.handler;

import org.w3c.dom.Element;

import com.alogic.metrics.Fragment;
import com.alogic.metrics.stream.MetricsCollector;
import com.alogic.metrics.stream.MetricsHandlerFactory;
import com.anysoft.rrm.RRData;
import com.anysoft.stream.AbstractHandler;
import com.anysoft.stream.Handler;
import com.anysoft.util.Properties;
import com.anysoft.util.Settings;

/**
 * 转换模型，进入指标处理流
 * 
 * @author duanwaiwai
 * @since 1.6.12.32 [20190429] <br>
 */
public class MetricsPorter extends AbstractHandler<RRData> implements MetricsCollector {
	Handler<Fragment> handler = MetricsHandlerFactory.getClientInstance();
	
    @Override
    protected void onHandle(RRData data, long timestamp) {
    	if (handler != null){
    		data.report(this, Settings.get());
    	}
    }

    @Override
    protected void onFlush(long timestamp) {

    }

    @Override
    protected void onConfigure(Element e, Properties p) {

    }

	@Override
	public void metricsIncr(Fragment f) {
		handler.handle(f, System.currentTimeMillis());
	}
}
